package com.ashleyleung.jetpack_b_station.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.ashleyleung.jetpack_b_station.lifecycle.ILifeCycle
import com.ashleyleung.jetpack_b_station.lifecycle.ILifeCycleOwner
import com.ashleyleung.jetpack_b_station.lifecycle.LifeCycleProvider
import com.ashleyleung.jetpack_b_station.lifecycle.LifeState
import com.ashleyleung.jetpack_b_station.musicList.MusicPresenter

/**
 * @author lxy
 * @name
 * @class describe
 * @date 2022-06-23
 * Copyright (c)  Guangzhou GCI Science & Technology Co., Ltd.All rights reserved
 */
open class BaseActivity : AppCompatActivity(), ILifeCycleOwner {

//    private val lifecycleListener = arrayListOf<ILifeCycle>()

    val lifeProvider by lazy {

        LifeCycleProvider() }

//    fun addLifeListener(listener: ILifeCycle) {
//        if (!lifecycleListener.contains(listener))
//            lifecycleListener.add(listener)
//    }
//
//    fun removeLifeListener(listener: ILifeCycle) {
//        lifecycleListener.remove(listener)
//    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

//        lifecycleListener.forEach { it.onCreate() }
        lifeProvider.makeLifeState(LifeState.CREATE)

    }

    override fun onStart() {
        super.onStart()
//        lifecycleListener.forEach { it.onStart() }
        lifeProvider.makeLifeState(LifeState.START)
    }

    override fun onStop() {
        super.onStop()
        lifeProvider.makeLifeState(LifeState.STOP)
//        lifecycleListener.forEach { it.onStop() }
    }

    override fun onDestroy() {
        super.onDestroy()
        lifeProvider.makeLifeState(LifeState.DESTROY)
//        lifecycleListener.forEach { it.onDestroy() }
    }

    override fun onPause() {
        super.onPause()
        lifeProvider.makeLifeState(LifeState.PAUSE)
//        lifecycleListener.forEach { it.onPause() }
    }

    override fun onResume() {
        super.onResume()
        lifeProvider.makeLifeState(LifeState.RESUME)
//        lifecycleListener.forEach { it.onResume() }
    }

    override fun getLifecycleProvider(): LifeCycleProvider {
        return lifeProvider
    }

}